import {defHttp} from '/@/utils/http/axios';
import {LoginParams, LoginResultModel, GetUserInfoModel} from '../model/userModel';

import {ErrorMessageMode} from '/#/axios';
import { getRouterListResultModel} from "/@/api/model/routerModel";

enum Api {
    Login = '/user/login',
    Logout = '/logout',
    GetUserInfo = '/user',
    GetPermCode = '/access/perm_code',
    GetRouterList = '/access/router_tree',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
    return defHttp.post<LoginResultModel>(
        {
            url: Api.Login,
            params,
        },
        {
            errorMessageMode: mode,
        },
    );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
    return defHttp.get<GetUserInfoModel>({url: Api.GetUserInfo}, {errorMessageMode: 'none'});
}

export function getPermCode() {
    return defHttp.get<string[]>({url: Api.GetPermCode});
}

export const getRouterList = () => {
    return defHttp.get<getRouterListResultModel>({url: Api.GetRouterList});
};

export function doLogout() {
    return defHttp.get({url: Api.Logout});
}
